/*
 * Copyright (C) 2013
 * Shopping
 */
package com.mshopping.app.entity;

import org.json.JSONException;
import org.json.JSONObject;

import com.mshopping.app.util.LogFactory;

/**
 * This class is used for ...
 * 
 * @author liuhuan
 * @version 1.0, 2013-9-3 下午10:33:08
 */
public class User extends BaseModel {

	private static final long serialVersionUID = -5444978013086978196L;
	private static final String KEY_USERNAME   = "username";
	private static final String KEY_ID 		   = "id";
	private static final String KEY_GRADE      = "grade";

	private int id = 0;
	private String name = "";
	private Double grade = 0.0; 
	
	public Double getGrade() {
		return grade;
	}

	public void setGrade(Double grade) {
		this.grade = grade;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public void unpack(JSONObject jsonData) {
		if (jsonData == null) {
			return;
		}
		try {
			
			if (jsonData.has(KEY_USERNAME)) {
				this.name = jsonData.getString(KEY_USERNAME);
			}
			if(jsonData.has(KEY_ID)){
				this.id = jsonData.getInt(KEY_ID);
			}
			if (jsonData.has(KEY_GRADE)) {
				this.grade = jsonData.getDouble(KEY_GRADE);
			}
			
		} catch (JSONException e) {
			e.printStackTrace();
			LogFactory.createLog().e(e);
		}
	}

}
